<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="[
          { name: 'box-base', title: '基础信息' },
          { name: 'box-form', title: '表单按钮' },
          { name: 'box-list', title: '列表按钮' },
          { name: 'box-line', title: '行内按钮' },
        ]"
      />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="节点名称" name="name" :parent="_self" :form="form" />
          <customFormItem label="节点值" name="value" :parent="_self" :form="form" />
          <customFormItem label="排序" name="sort" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name" />
          <div class="label-class w-280">
            <strong>颜色</strong> <t-color-picker class="label-picker" v-model="form.color" />
          </div>
          <div id="box-form" class="box-title">表单按钮</div>
          <customFormItem label="添加按钮" name="flagShowVfbAdd" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <customFormItem label="保存按钮" name="flagShowVfbSave" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <customFormItem label="删除按钮" name="flagShowVfbDelete" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <div id="box-list" class="box-title">列表按钮</div>
          <customFormItem label="添加按钮" name="flagShowVbAdd" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <customFormItem label="刷新按钮" name="flagShowVbRefresh" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <customFormItem label="删除按钮" name="flagShowVbDelete" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <div id="box-line" class="box-title">行内按钮</div>
          <customFormItem label="编辑按钮" name="flagShowVrbEdit" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <customFormItem label="删除按钮" name="flagShowVrbDelete" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
          <customFormItem label="查看按钮" name="flagShowVrbView" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" />
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  created() {
    let that = this
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.form.flowId = initData.id
        if (this.strings.isBlank(this.form.color)) {
          this.$set(this.form, 'color', '#000000')
        }
        this.$set(this.form, 'flagShowVfbAdd', this.form.flagShowVfbAdd == undefined ? true : this.form.flagShowVfbAdd)
        this.$set(this.form, 'flagShowVfbSave', this.form.flagShowVfbSave == undefined ? true : this.form.flagShowVfbSave)
        this.$set(this.form, 'flagShowVfbDelete', this.form.flagShowVfbDelete == undefined ? true : this.form.flagShowVfbDelete)
        this.$set(this.form, 'flagShowVrbEdit', this.form.flagShowVrbEdit == undefined ? true : this.form.flagShowVrbEdit)
        this.$set(this.form, 'flagShowVrbView', this.form.flagShowVrbView == undefined ? true : this.form.flagShowVrbView)
        this.$set(this.form, 'flagShowVrbDelete', this.form.flagShowVrbDelete == undefined ? true : this.form.flagShowVrbDelete)
        this.$set(this.form, 'flagShowVbAdd', this.form.flagShowVbAdd == undefined ? true : this.form.flagShowVbAdd)
        this.$set(this.form, 'flagShowVbRefresh', this.form.flagShowVbRefresh == undefined ? true : this.form.flagShowVbRefresh)
        this.$set(this.form, 'flagShowVbDelete', this.form.flagShowVbDelete == undefined ? true : this.form.flagShowVbDelete)
      },
      afterSave: () => {},
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {},
      beforeClose: () => {
        return true
      },
      afterClick() {},
    })
  },
  props: ['propPrimaryKey', 'propDictionaries', 'propCurrentRow', 'propViewFormData', 'propReadonly', 'propStatus', 'propRules', 'propInitData'],
  components: { customAnchor },
  computed: {},
  watch: {
    currentRow: {
      immediate: true,
      handler(newValue) {

      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .label-picker {
    display: inline-block;
    vertical-align: middle;
  }
</style>
